<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="bean.dal.*,bean.entity.*"%>
<%@page import="bean.common.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<jsp:include page="top.jsp"></jsp:include>
    <!-- 创建标题容器 -->
    <div class="mycredits">
        <h1>
            管理积分券
        </h1>
    </div>
    <!-- 创建一个外层容器 -->
    <div class="outer-wrapper" style="border: 1px solid white;">
    
		 <%
			 CreditManager orderM = new CreditManager();
	String userid = (String) session.getAttribute("userid");
			 
		    int pagesize = 15;//页面大小
		    int recordCount ;//记录总数
		    int pageCount;//页面总数
		    int pageid;//页面号
		    int newsTypeId=0;
		    String  strpageid = request.getParameter("pageid");
		    if(strpageid==null ) pageid=1;
		       else pageid = Integer.parseInt(strpageid); 
		    if(pageid < 1) pageid = 1;
    		recordCount =  orderM.getRecordCountAll();
		    if(recordCount%pagesize==0) pageCount =  recordCount/pagesize ;
		      else pageCount =  recordCount/pagesize +1;
		    if(pageCount<=0) pageCount=1;
   			 if(pageid > pageCount) pageid=pageCount;
    		System.out.println(recordCount);
			 
		    //通过JavaBean的getUsersBypageid(pageid,pagesize)读取某页的记录数据
		  	ArrayList<Credit> creditlist=null;
		 	Iterator<Credit> it = null;
		 	Credit credit = null;
		    creditlist = orderM.getCreditAll(pageid, pagesize);
		    //newsmanager.closeConn();//不再访问数据库，关闭连接
		    
		    //通过迭代器，列表显示每条记录，并做查看、删除链接
		 	if(creditlist!=null){	   it = creditlist.iterator();}
		 	
		 	while(it!=null&&it.hasNext()){
		 		credit =  it.next();
		 %>
        <div class="outer">
            <!-- 创建图片容器 -->
            <div class="img-wrapper">
                <!-- 设置图片 -->
            </div>
            <!-- 创建内容区容器 -->
            <div class="info">
                <h2 class="title">
                    <%=credit.getCreditname() %>
                </h2>
                <p class="intro">
					<%=credit.getIntroduce() %>
                </p>
                <h3 class="category">
                    <i class="iconfont icon-jifen"></i>
                  优惠 价格：<%=credit.getPrice() %>
                </h3>
                <h3 class="category">
                    <i class="iconfont icon-jifen"></i>
                    所需积分：<%=credit.getCredit() %>
                </h3>
                <h3 class="category">
                    <i class="iconfont icon-jifen"></i>
                    剩余数量:<%=credit.getQuantity() %>
                </h3>
            </div>
            <!-- 创建兑换按钮 -->
            <div class="button-wrapper">
            	<a href="/express/servlet/Creditex?modth=convert&id=<%=credit.getId() %>&integration=<%=credit.getCredit() %>&userid=<%=userid %>&price=<%=credit.getPrice() %>">
                    <input type="button" value="兑换" />
                </a>
            </div>
        </div>
		<%} %>
    </div>
    <!-- 创建按钮 -->
    <div class="button">
        <a href="user/index.jsp">
            <input type="button" value="返回" />
        </a>
    </div>
</body>

</html>